<?php

require_once("function.php");

class Manager
{
	function movePlanholder($planholder, $employee)
	{
		$con = connectToDB();
		
		$result = mysql_query("update planholder set Account_executive = '$employee' where Policy_no = '$planholder'");
		
		mysql_close($con);
	}
	
	function viewEmployees($manager_no)
	{
		$con = connectToDB();
		
		$result = mysql_query("select * from employee right join (select * from manages where EMPLOYEE_Manager_no = '$manager_no') m on employee.Emp_no = m.EMPLOYEE_Emp_no");
		
		mysql_close($con);
		return $result;
	}
	
	function viewOtherEmployees($manager_no)
	{
		$con = connectToDB();
		
		$result = mysql_query("select * from employee right join (select * from manages where EMPLOYEE_Manager_no <> '$manager_no') m on employee.Emp_no = m.EMPLOYEE_Emp_no");
		
		mysql_close($con);
		return $result;
	}
	
	function viewEmployeePlanholders($employee)
	{
		$con = connectToDB();
		
		$result = mysql_query("select * from planholder where Account_executive = '$employee'");
		
		mysql_close($con);
		return $result;
	}
	function addEmployee($managerNo, $employeeNo)
	{
		$conto = connectToDB();		
		$employeeNo = mysql_real_escape_string($employeeNo);
		$managerNo = mysql_real_escape_string($managerNo);
		
		$result = mysql_query("INSERT INTO employee (Emp_no,Pos) VALUES('$employeeNo','Regular')");
		$result = mysql_query("insert into manages values('$managerNo','$employeeNo')");
	}
	
	function deleteEmployee($empno){
		$con2 = connectToDB();
		$empno = mysql_real_escape_string($empno);
		
		//mysql_select_db("apodb", $con);
		$result = mysql_query("delete from manages where EMPLOYEE_Emp_no ='$empno'");
		$result2 = mysql_query("DELETE FROM employee WHERE Emp_no='$empno'");
		if($result && $result2)
			return true;
		else
			return false;
		
	}
}

?>